Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: make code cache and snapshot deterministic #29142

Closed
wants to merge 3 commits into from

Conversation

bnoordhuis
Copy link
Member

Use a fixed random seed to ensure that the generated sources are
identical across runs.

The final node binary still reseeds itself on start-up so there should
be no security implications caused by predictable random numbers (e.g.,
Math.random(), ASLR, the hash seed, etc.)

Fixes: #29108

Use a fixed random seed to ensure that the generated sources are
identical across runs.

The final node binary still reseeds itself on start-up so there should
be no security implications caused by predictable random numbers (e.g.,
`Math.random()`, ASLR, the hash seed, etc.)

Fixes: nodejs#29108
@nodejs-github-bot nodejs-github-bot added the tools Issues and PRs related to the tools directory. label Aug 15, 2019
@nodejs-github-bot
Copy link
Collaborator

@@ -26,6 +26,8 @@ int wmain(int argc, wchar_t* argv[]) {
int main(int argc, char* argv[]) {
#endif // _WIN32

v8::V8::SetFlagsFromString("--random_seed=42");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@bnoordhuis
Copy link
Member Author

Hrm, looks like retrieval from the cache fails unless node is also started with --random_seed=42. The hash of the command line flags is part of the code cache's checksum.

I can work around that by resetting --random_seed=0 just before creating the code cache. Not super elegant but it does the trick. It's interesting that snapshot creation is unaffected.

@devsnek
Copy link
Member

devsnek commented Aug 15, 2019

also @nodejs/v8

@ChALkeR
Copy link
Member

ChALkeR commented Aug 15, 2019

Also /cc @nodejs/security @indutny just in case.

Thought I don't see how the seed for static (i.e. shared across runs and public) cache generation should affect security (for the reasons stated in #29108).

@joyeecheung
Copy link
Member

@Trott
Copy link
Member

Trott commented Aug 19, 2019

Hrm, looks like retrieval from the cache fails unless node is also started with --random_seed=42. The hash of the command line flags is part of the code cache's checksum.

I can work around that by resetting --random_seed=0 just before creating the code cache. Not super elegant but it does the trick. It's interesting that snapshot creation is unaffected.

@bnoordhuis Would I be correct to conclude from the above comments that this shouldn't land yet?

@bnoordhuis
Copy link
Member Author

@Trott I incorporated the necessary fixes. bnoordhuis/io.js@ed2c673 is the fix but the timestamp may be throwing off GH because it shows up before my comment.

@Trott
Copy link
Member

Trott commented Aug 20, 2019

Landed in 5116a6a

@Trott Trott closed this Aug 20, 2019
Trott pushed a commit that referenced this pull request Aug 20, 2019
Use a fixed random seed to ensure that the generated sources are
identical across runs.

The final node binary still reseeds itself on start-up so there should
be no security implications caused by predictable random numbers (e.g.,
`Math.random()`, ASLR, the hash seed, etc.)

Fixes: #29108

PR-URL: #29142
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
targos pushed a commit that referenced this pull request Aug 20, 2019
Use a fixed random seed to ensure that the generated sources are
identical across runs.

The final node binary still reseeds itself on start-up so there should
be no security implications caused by predictable random numbers (e.g.,
`Math.random()`, ASLR, the hash seed, etc.)

Fixes: #29108

PR-URL: #29142
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
@bnoordhuis bnoordhuis deleted the fix29108 branch August 20, 2019 10:43
@ChALkeR
Copy link
Member

ChALkeR commented Aug 20, 2019

@bnoordhuis Yes, I can confirm that this fixes the issue. Thanks!
Unzipping the same archive and building on Linux in the same path now produces identical results (zero differences between the dirs produced on two consecutive runs).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tools Issues and PRs related to the tools directory.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

node_code_cache.cc and node_snapshot.cc generation is unreproducible
8 participants